package learn.euraka.hystrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author： xiami
 * @Date： Created in 2018-03-25 22:27
 * @Modified By：
 */
@Service
public class ComputeService {

    private static Logger logger = LoggerFactory.getLogger(ComputeService.class);

    @Resource
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "addFallback")
    public String add() {
        String body = restTemplate.getForEntity("http://eureka-service/add?a=10&b=20", String.class).getBody();
        logger.debug("body = " + body);
        return body;
    }

    public String addFallback() {
        return "error";
    }

}
